/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import Enum.LoaiNguoiDungEnum;
import java.util.List;
import org.hibernate.Session;
import pojo.NguoiDung;
import util.NewHibernateUtil;

/**
 *
 * @author 0
 */
public class CuaHangDAO extends BaseDAO{
    public static List<?> LayDanhSach(Class<?> clazz,NguoiDung nguoiDung) throws Exception{
        Session session=NewHibernateUtil.getSessionFactory().openSession();
        String string=String.format("from %s o where (o.isDelete=false or o.isDelete=null)",clazz.getName());
        if(nguoiDung.getLoaiNguoiDung().getId()!=LoaiNguoiDungEnum.Admin.getCode()){
            string+=String.format(" and o.id=%d",nguoiDung.getCuaHang().getId());
        }
        List<?> list=session.createQuery(string).list();
        session.close();
        return list;
    }
}
